#include "./LaunchEvent.h"

using namespace Commands;

LaunchEvent::LaunchEvent( EventType type, GameLogic::Objects::GameObject* arg1, GameLogic::Objects::GameObject* arg2 ) :
	type_( type )
,	arg1_( arg1 )
,	arg2_( arg2 )
{}

void LaunchEvent::execute( GameLogic::Simulation* s ) {
	switch( type_ ) {
	case onHitImpassableTile:
		arg1_->onHitImpassableTile();
		break;
	case onHit:
		arg1_->onHit( arg2_ );
		arg2_->onHit( arg1_ );
		break;
	}
}

void LaunchEvent::serialize( std::ostringstream& s ) {
	s << Network::UDPIO::EVENT << SEPARATOR;
	s << type_ << SEPARATOR;
	s << arg1_->getId().toNumeric() << SEPARATOR;
	if( arg2_ != 0 )
		s << arg2_->getId().toNumeric();
	else
		s << GameLogic::Objects::GameObject::IdType::INVALID_ID.toNumeric();
}
